<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of report
 *
 * @author Константин Охотник
 */

class Settings extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->issetSession('Settings');
        $this->load->model('SettingsModel');
    }
    
    public function index()
    {
        redirect('/settings/acc');
    }
    
    public function categories()
    {
        $result = $this->SettingsModel->getCategories();
        $this->SettingsModel->assign('result',$result)->display('settings.tpl');
    }
    
    public function addcategory()
    {
        die( $this->SettingsModel->AddCategory($this->input->post()));
    }
    
    public function deletecategory($id)
    {
        $this->SettingsModel->delete_post('gl_categories', 'id', $id);
        redirect('/settings/categories');
    }
    
    public function updatecategory()
    {
        $data = $this->input->post();
        $id = $data['id'];
        unset($data['id']);
        die($this->SettingsModel->update_post('gl_categories', 'id', $id, $data));
    }
	
    public function acc()
    {
        $result = $this->SettingsModel->get_array('tb_person');
        $this->SettingsModel->assign('result',$result)->display('settings_access.tpl');
    }

    public function addperson()
    {
        die( $this->SettingsModel->AddPerson($this->input->post()));
    }
    
    public function deleteperson($id)
    {
        $s = $this->session->getSession();

        if( $id == $s['userdata'][1])
        {
            redirect('/settings/acc');
        }
        else
        {
            $this->SettingsModel->delete_post('tb_person', 'id', $id);
            redirect('/settings/acc');	
        }
    }
    
    
    public function updateperson()
    {
        $data = $this->input->post();
        $id = $data['id'];
        unset($data['id']);
        die($this->SettingsModel->update_post('tb_person', 'id', $id, $data));
    }
    
    public function deletesite($id)
    {
        $s = $this->session->getSession();
        $r = $this->SettingsModel->delete_post('gl_site', 'id', $id);
        redirect('/settings/site');	
    }
    
    public function addsite()
    {
        die( $this->SettingsModel->AddSite($this->input->post()));
    }
    
    public function updatesite()
    {
        $data = $this->input->post();
        $id = $data['id'];
        unset($data['id']);
        die($this->SettingsModel->update_post('gl_site', 'id', $id, $data));
    }
    
    public function site()
    {
        $result = $this->SettingsModel->getSites();
        $this->SettingsModel->assign('result',$result)->display('site.tpl');
    }
}